#include "Logging.hxx"

void log_initialize()
{
    try
    {
        auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
        console_sink->set_level(spdlog::level::trace);
        console_sink->set_pattern("[VideoAnnotator] [%^%l%$] %v");

        auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/VideoAnnotator.txt", true);
        file_sink->set_level(spdlog::level::trace);

        spdlog::sinks_init_list sink_list = { file_sink, console_sink };

        spdlog::logger logger("VideoAnnotator", sink_list.begin(), sink_list.end());
        logger.set_level(spdlog::level::trace);
        logger.info("Initialized Logging System.");

        // or you can even set multi_sink logger as default logger
        auto sys_logger = std::make_shared<spdlog::logger>("VideoAnnotator", spdlog::sinks_init_list({ console_sink, file_sink }));
        spdlog::set_default_logger(sys_logger);

        sys_logger->set_level(spdlog::level::trace);
    }
    catch (const spdlog::spdlog_ex& ex)
    {
        std::cout << "Log initialization failed: " << ex.what() << std::endl;
    }
}

void log_shutdown()
{
    spdlog::drop_all();
}